import { defineStore } from "pinia";
import { ref } from "vue";
import { service } from "/@/cool";

export const useSessionStore = defineStore("chat-session", () => {
	// 加载状态
	const loading = ref(false);

	// 列表
	const list = ref<any[]>([]);

	// 选中
	const value = ref<any>();

	// 获取列表
	async function get() {
		loading.value = true;
		if (!value.value) {
			set([]);
		}

		// 设置列表
		list.value = [];
		// 发送请求
		const res = await service.socket.list.list();
		list.value = res;
		set(list.value[0]);
		loading.value = false;
	}

	// 设置值
	function set(data: any) {
		// 设置值
		value.value = data;
	}

	return {
		loading,
		list,
		value,
		get,
		set
	};
});
